package service

import (
	"BiYeProServer/src/model"
	"BiYeProServer/src/model/dao"
	"BiYeProServer/src/util"
	"github.com/gin-gonic/gin"
)

func Register(ctx *gin.Context){
	var user model.User
	err := ctx.ShouldBind(&user)
	if err != nil {
		util.SetResponse(ctx,5002,false,nil,"注册错误，请检查参数是否正确")
		return
	}
	u := dao.SelectUserByUname(ctx,user.Username)
	if u != nil && u.Username != ""{
		util.SetResponse(ctx,5003,false,nil,"用户名已经存在，请更改用户名")
		return
	}
	dao.GetDb().Create(&user)
	util.SetResponse(ctx,200,true,user,"注册成功")
}
